<?php
class LoginAction extends Action {
	public function index() {
		$this->display ();
	}
	function login() {
		$Admin = M('Admin');
		$admin_user = $Admin->where(array('admin_name'=>$this->_post('admin_name')))->find();
		if($admin_user){
			if($admin_user['admin_password'] == md5($this->_post('admin_password'))){
				session('admin_user',$admin_user);
				$this->redirect('Index/index');
			}else{
				$this->error('密码输入错误！');
			}
		}else{
			$this->error('没有此管理员！');
		}
	}
	
	function editPassword(){
		$Admin = M('Admin');
		$Admin->where('admin_id = '.$_SESSION['admin_user']['admin_id'])->data(array('admin_password'=>md5($this->_post('admin_password'))))->save();	
		echo 1;
	}
	
	function logout(){
		session('admin_user',null);
		$this->redirect('index');
	}
}